<?php include("include/textcenter.php"); ?>
<?php include("include/db.php"); ?>
<?php include("include/fn.php"); ?>
<?php
    $orderid = $_GET['orderid'];
    $BuyerID = $_GET['id'];
    $ProductID = $_GET['pro'];
    $Amount='1';
    $ActiveYN = '1';
function number($length)
{
   $array = array();
   for($i=0;$i<$length;$i++)
         $key .= rand(0,9);
   
   return $key;
}
$GiftCardNo = number(16);
$sql = "select count(GiftCardNo) as total from vnf_giftcard where GiftCardNo='$GiftCardNo'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
    if($row['total']==0)
    {
        $sql = "insert into vnf_giftcard(GiftCardNo, Amount, ActiveYN, BuyerID) values(
        '".$GiftCardNo."', '".$Amount."', '".$ActiveYN."', '".$BuyerID."'
        )";
        mysql_query($sql);
       /* $sql = "select * from vnf_customer where CustomerNo='$BuyerID'";
        $customer = mysql_query($sql);
        while($cus =mysql_fetch_array($customer))
        {
            $to  = $cus['Email']; // note the comma
            echo $to;
            // subject
            $subject = 'Your giftcard';
            
            // message
            $message = '
            <html>
            <head>
              <title>Your giftcard</title>
            </head>
            <body>
              <table>
                <tr>
                  <th width="150px">GiftCardNo</th><th width="80px">Amount</th>
                </tr>
                <tr>
                  <td>'.$GiftCardNo.'</td><td style="text-align:center;">'.$Amount.'</td>
                </tr>
              </table>
            </body>
            </html>
            ';
            echo $message;
            // To send HTML mail, the Content-type header must be set
            //$headers  = 'MIME-Version: 1.0' . "\r\n";
            $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
            // Additional headers
            $headers .= 'To: '.$cus['Email'].'' . "\r\n";
            $headers .= 'From: <info@skinspastore.com>' . "\r\n";
            $headers .= 'Bcc:  ptp285@gmail.com' . "\r\n";
            // Mail it
            mail($to, $subject, $message, $headers);
        }*/
        $sql = "update vnf_product set GiftcardYN='Sent' where ProductNo='$ProductID'";
        mysql_query($sql);
        // multiple recipients
        echo '<meta http-equiv="Refresh" content="0;URL=order_detail.php?id='.$orderid.'" />'; 
    }
}
?>